package com.feicheng.common.mqtt;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.util.StringGenerator;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;

import java.util.HashMap;

public class MqttCmd extends JSONObject {

    public static HashMap<String, String> IDS = new HashMap<>();

    private MqttCmd(String operator, JSON info) {
        this.put("operator", operator);
        this.put("messageId", StringGenerator.getID("MQTTMSG"));
        if (null == info) {
            info = new JSONObject();
        }
        this.put("info", info);
    }

    public JSONObject getInfoObject() {
        return this.getJSONObject("info");
    }

    public JSONArray getInfoArray() {
        return this.getJSONArray("info");
    }

    public static class Builder {
        private String operator;
        private String messageId;
        private JSON info;

        public Builder operator(String operator) {
            this.operator = operator;
            return this;
        }

        public Builder info(JSON info) {
            this.info = info;
            return this;
        }

        public MqttCmd build() {
            return new MqttCmd(this.operator, this.info);
        }
    }

    public static class Person {
        private String customId;
        private String name;
        private Integer personType = 0; //0: 白名单
        private Integer tempCardType = 1; // 1:临时名单 1(时间段有效)
        private String cardValidBegin;
        private String cardValidEnd;
        private String picURI;

        public Person customId(String customId) {
            this.customId = StringGenerator.getID("MQCT");
            IDS.put(this.customId, customId);
            return this;
        }

        public Person name(String name) {
            this.name = name;
            return this;
        }

        public Person personType(Integer personType) {
            this.personType = personType;
            return this;
        }

        public Person tempCardType(Integer tempCardType) {
            this.tempCardType = tempCardType;
            return this;
        }

        public Person cardValidBegin(String cardValidBegin) {
            this.cardValidBegin = cardValidBegin;
            return this;
        }

        public Person cardValidEnd(String cardValidEnd) {
            this.cardValidEnd = cardValidEnd;
            return this;
        }

        public Person picURI(String picURI) {
            this.picURI = picURI;
            return this;
        }

        public JSONObject build() {
            JSONObject res = new JSONObject();
            res.put("customId", this.customId);
            res.put("name", this.name);
            res.put("personType", this.personType);
            res.put("tempCardType", this.tempCardType);
            res.put("cardValidBegin", this.cardValidBegin);
            res.put("cardValidEnd", this.cardValidEnd);
            res.put("picURI", this.picURI);
            return res;
        }
    }

}
